package com.feng.annotation;

import com.feng.annotation.bean.Car;
import com.feng.annotation.bean.Person;
import com.feng.annotation.beanPostProcess.MyBeanPostProcess;
import com.feng.annotation.conditional.MyConditional;
import com.feng.annotation.controller.PersonController;
import com.feng.annotation.service.PersonService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * Hello world!
 */
@ComponentScan(value = "com.feng.annotation",useDefaultFilters = false,
        includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Component.class})},
        excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = {Service.class, Controller.class})}
)
@Import(value = {MyBeanPostProcess.class})
@Configuration
public class HelloworldApplication {

//    @Lazy
//    @Bean(initMethod = "init", destroyMethod = "destroy")
    @Bean
    public Person person(){
        return new Person(1,"liqingfeng",24);
    }

    @Conditional(MyConditional.class)
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Bean
    public PersonController personController(){
        return  new PersonController();
    }

    @Conditional(MyConditional.class)
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Bean
    public PersonService personService(){
        return  new PersonService();
    }

    @Profile("dev")
    @Bean
    public Car car(){
        return new Car();
    }

}
